from dtos.result import Result


class VerifyFunc(object):
    @classmethod
    def verify_length(cls, v, _len=10):
        res = len(v) <= _len
        if not res:
            return Result.error_result(message="长度约束检查未通过，约束值为:%s" % str(_len))
        return Result.success_result()

    @classmethod
    def is_list(cls, v):
        if not isinstance(v, list):
            return Result.error_result(message="数据需要为list形式")
        return Result.success_result()

    @classmethod
    def is_dict_or_list(cls, v):
        if not isinstance(v, list) and not isinstance(v, dict):
            return Result.error_result(message="参数值需要list或dict的形式")
        return Result.success_result()
